<%@ page language="java" contentType="text/html; charset=UTF-8"%>
<%@include file="/include/common/gridbackhead.jsp"%>
<%!
private class PageAction extends BaseAction{
	ResultSet rs = null;
	String firstSn = "";
	//准备action的环境变量 每次请次都会执行此方法 可在此方法中初如化一些变量
	protected void prepareActionEnv() throws Exception{
		
	}
	
	protected void EndProcess() throws Exception{
		form.spsv("firstSn", firstSn);
	}
	
	protected boolean onLoadDefault() throws Exception{
		onSearchRetrieveResult();
		return true;
	}
	
	// 取出查询結果
	protected void onSearchRetrieveResult() throws Exception{
		String sql = onSearchGetSql();
		if(sql == null){ret.setErrorInfo("查询语句异常,请联系资讯部!");return;}
		rs = utils.executeQuery("info5",sql);
		BaseDataEntities rows = new BaseDataEntities();
		Map map = new HashMap();
		while(rs.next()){
			BaseDataEntity row1 = null;//公司別
			BaseDataEntity row2 = null;//部門
			BaseDataEntity row3 = new BaseDataEntity();//ip
			
			String key1 = utils.getRsString(rs,"hr003atsn");
			String key2 = utils.getRsString(rs,"hr003atsn")+","+utils.getRsString(rs,"hr003tsn");
			
			if(map.containsKey(key1)){
				row1 = (BaseDataEntity)map.get(key1);
			}else{
				row1 = new BaseDataEntity();
				row1.spsv("name", utils.getRsString(rs, "hr003aname"));
				row1.spsv("open", "true");
				row1.spov("children", new BaseDataEntities());
				rows.add(row1);
				map.put(key1, row1);
			}
			
			if(map.containsKey(key2)){
				row2 = (BaseDataEntity)map.get(key2);
			}else{
				row2 = new BaseDataEntity();
				row2.spsv("name", utils.getRsString(rs, "hr003name"));
				row2.spov("children", new BaseDataEntities());
				row1.gpdes("children").add(row2);
				map.put(key2, row2);
			}
			row3.spsv("name", utils.getRsString(rs, "ip"));
			row3.spsv("sn", utils.getRsString(rs, "sn"));
			row2.gpdes("children").add(row3);
			
			if(rows.size() == 1){
				firstSn = row3.gpsv("sn");
			}
		}
		ret.SetSearchResult(rows);
	}
	
	//取出查詢語句
	protected String onSearchGetSql() throws Exception{
		StringBuilderEx sql =  new StringBuilderEx("select * from pan..PAN_SUBPRO_APPIP order by hr003atsn,hr003name ,ip");
		return sql.toString();
	}

}
%>
<%@include file="/include/common/gridbackend.jsp"%>
